package net.neptech.utils;

import java.util.HashSet;
import java.util.Set;

/**
 * 上传会话上下文（存储在 Redis 中）
 */
public class UploadContext {
    private String fileId;
    private String filename;
    private String objectName; // 最终对象名
    private long fileSize;
    private int totalChunks;
    private Set<Integer> uploadedChunks = new HashSet<>();
    private long expireTime;
    private String uploadDir; // ✅ 新增：分片存放目录

    // ✅ 在这里添加 isExpired() 方法
    /**
     * 判断上传会话是否已过期
     * @return true 如果已过期
     */
    public boolean isExpired() {
        return System.currentTimeMillis() > expireTime;
    }
    public UploadContext(String fileId, String filename, String objectName, long fileSize, int totalChunks) {
        this.fileId = fileId;
        this.filename = filename;
        this.objectName = objectName;
        this.fileSize = fileSize;
        this.totalChunks = totalChunks;
        this.uploadedChunks = new HashSet<>();
        this.uploadDir = "chunks/" + fileId;
        this.expireTime = System.currentTimeMillis() + 3600_000; // 可配置
    }

    public UploadContext() {
    }

    public UploadContext(String fileId, String filename, String objectName, long fileSize, int totalChunks, Set<Integer> uploadedChunks, long expireTime, String uploadDir) {
        this.fileId = fileId;
        this.filename = filename;
        this.objectName = objectName;
        this.fileSize = fileSize;
        this.totalChunks = totalChunks;
        this.uploadedChunks = uploadedChunks;
        this.expireTime = expireTime;
        this.uploadDir = uploadDir;
    }

    public String getFileId() {
        return fileId;
    }

    public void setFileId(String fileId) {
        this.fileId = fileId;
    }

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public String getObjectName() {
        return objectName;
    }

    public void setObjectName(String objectName) {
        this.objectName = objectName;
    }

    public long getFileSize() {
        return fileSize;
    }

    public void setFileSize(long fileSize) {
        this.fileSize = fileSize;
    }

    public int getTotalChunks() {
        return totalChunks;
    }

    public void setTotalChunks(int totalChunks) {
        this.totalChunks = totalChunks;
    }

    public Set<Integer> getUploadedChunks() {
        return uploadedChunks;
    }

    public void setUploadedChunks(Set<Integer> uploadedChunks) {
        this.uploadedChunks = uploadedChunks;
    }

    public long getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(long expireTime) {
        this.expireTime = expireTime;
    }

    public String getUploadDir() {
        return uploadDir;
    }

    public void setUploadDir(String uploadDir) {
        this.uploadDir = uploadDir;
    }
}
